package com.sunny.example.string;

import java.util.Scanner;

/**
 * 字符串序列判定
 * 针对存在重复字符的S，题目中没有规定要怎么处理？
 */
public class String0101 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            String[] inputs = new String[2];
            for (int i = 2; i > 0; i--) {
                inputs[inputs.length - i] = scanner.nextLine();
            }
            String S = inputs[0];
            String L = inputs[1];
            if (null == S || "".equals(S) || S.length() > 100 || null == L || "".equals(L) || L.length() > 50000) {
                continue;
            }
            //1、如果S是连续子串，在L中
            if (L.contains(S)) {
                int indexStart = L.indexOf(S);
                System.out.println(indexStart + S.length());

            } else {
                //2、非连续子串
                int result = 0;
                int indexTmp = -1;
                for (int k = 0; k < S.length(); k++) {
                    //S中每个字符在L中的index，如果是按升序的，则为有效子串
                    int i = L.indexOf(S.charAt(k));
                    if (i < indexTmp || i == -1) {
                        result = -1;
                        break;
                    }
                    indexTmp = i;
                }
                if (result != -1) {
                    //有效子串
                    result = L.indexOf(S.charAt(S.length() - 1));
                }
                System.out.println(result);


            }
        }
    }
}
